package jfox.platform.aaa.entity;

import java.util.Arrays;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

import jfox.platform.common.Utils;
import jfox.platform.infrastructure.VersionableAndLocalNamingAndRefInspectableEntityObject;

/**
 * @author <a href="mailto:thaiguo@gmail.com">Taiguo Zhang</a>
 */

@Entity
@Table(name = "T_SYS_ROLE")
public class Role extends VersionableAndLocalNamingAndRefInspectableEntityObject{
	
	@Column(name = "NODES")
	private String nodes;

    private long[] nodesArray;

    public String getNodes() {
		return nodes;
	}

	public void setNodes(String nodes) {
		this.nodes = nodes;
	}

    public long[] getNodesArray(){
        if(nodesArray == null) {
            nodesArray = Utils.string2Array(nodes);
            Arrays.sort(nodesArray);
        }
        return nodesArray;
    }

    public boolean hasNode(long nodeId){
        return Arrays.binarySearch(getNodesArray(), nodeId) >= 0;
    }
   
}
